﻿package cn.lite3.air 
{
	import flash.display.NativeWindow;
	import flash.events.Event;
	import flash.events.NativeWindowDisplayStateEvent;
	
	/**
	 * www.lite3.cn
	 * lite3@qq.com
	 * @author lite3
	 */
	public class NatiaveWindowUtil 
	{
		
		/**
		 * 使窗口变成 模式的,就是其他窗口不能用
		 * @param	window
		 */
		static public function mackModal(window:NativeWindow):void
		{
			window.activate();
			window.orderToFront();
			window.addEventListener(Event.DEACTIVATE, deactivateHandler);
			window.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, displayStateChangingHandler);
			window.addEventListener(Event.CLOSING, closingHandler);
		}
		
		static private function deactivateHandler(e:Event):void 
		{
			(e.currentTarget as NativeWindow).activate();
		}
		
		static private function displayStateChangingHandler(e:NativeWindowDisplayStateEvent):void 
		{
			e.preventDefault();
		}
		
		static private function closingHandler(e:Event):void 
		{
			var window:NativeWindow = e.currentTarget as NativeWindow;
			window.removeEventListener(Event.DEACTIVATE, deactivateHandler);
			window.removeEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, displayStateChangingHandler);
			window.removeEventListener(Event.CLOSING, closingHandler);
		}
		
	}
	
}